package com.example.controller;

import com.example.entity.Img;
import com.example.interceptor.TokenNotValidation;
import com.example.mapper.ImgMapper;
import com.example.service.ImgService;
import com.example.utils.ImgUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;

@RestController
@RequestMapping("/file")
public class FileController {

    @Autowired
    ImgMapper imgMapper;

    @Autowired
    ImgUtil imgUtil;

    @Autowired
    ImgService imgService;

    //下载图片
    @TokenNotValidation
    @GetMapping("/img/{imgid}")
    public String im(HttpServletResponse response, @PathVariable Integer imgid) {
        Img img = imgMapper.selectByPrimaryKey(imgid);
        return imgUtil.downloadFile(img.getPath(), response);
    }

}
